#include "stdafx.h"
#include "wf_blocksattributes.h"

#include "pf_graphic.h"
#include "pf_dialogfactory.h"



WF_BlocksAttributes::WF_BlocksAttributes(
    PF_Container& container,
    PF_GraphicView& graphicView)
        :PF_ActionInterface("Edit Block Attributes", container, graphicView) {}




QAction* WF_BlocksAttributes::createGUIAction(LX_Define::ActionType /*type*/, QObject* /*parent*/) {
	// tr("Rename Block")
    QAction* action = new QAction(tr("&Rename Block"), NULL);
	action->setIcon(QIcon(":/ui/blockattributes.png"));
    //action->zetStatusTip(tr("Rename Block and all Inserts"));
    return action;
}



void WF_BlocksAttributes::trigger() {
    PF_DEBUG->print("editing block attributes");

    if (graphic!=NULL && PF_DIALOGFACTORY!=NULL) {
        PF_Block* block = graphic->getActiveBlock();
        PF_BlockList* blockList = graphic->getBlockList();
        if (blockList!=NULL && block!=NULL) {
            PF_String oldName = block->getName();

            PF_BlockAttribute d;
            d = PF_DIALOGFACTORY->requestBlockAttributesDialog(
                    blockList);

            if (d.isValid()) {

                PF_String newName = d.name;
                blockList->rename(block, newName);

                // update the name of all inserts:
                graphic->renameInserts(oldName, newName);

                graphic->addBlockNotification();
            }
        }

    }
    finish();
}



void WF_BlocksAttributes::init(int status) {
    PF_ActionInterface::init(status);
    trigger();
}

// EOF
